/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.figures;

import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Panel;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;

import edu.pku.sei.modeler.uml.ResourceFactory;

/**
 * @generated
 * 
 */
public class StateInvariantFigure extends CommonFigure {
	private final Label label;

	private final Panel panel;
	
	private boolean canMove = true;

	// TODO Remove and calculate based on text
	// private static final Dimension DEFAULT_SIZE = new Dimension(13,13);

	public StateInvariantFigure() {
		BorderLayout layout = new BorderLayout();
		setLayoutManager(layout);
		setBackgroundColor(ColorConstants.listBackground);

		label = new Label("State Invariant");
        label.setFont(ResourceFactory.getTextFont());
		panel = new Panel();
		panel.setLayoutManager(new ToolbarLayout(ToolbarLayout.HORIZONTAL));
		panel.add(new Label("{"));
		panel.add(label);
		panel.add(new Label("}"));

		add(panel, BorderLayout.CENTER);
	}
//
	protected boolean useLocalCoordinates() {
		return true;
	}

	// --- ILabeledFigure ---

	public Rectangle getLabelBounds() {
		Rectangle rect = label.getClientArea().getCopy();
		label.translateToAbsolute(rect);
		return rect;
	}

	public void setLabel(String labelText) {
		label.setText(labelText);
		// repaint();
//		invalidate();
//		validate();
	}
	
	 public void setCanMove(boolean canMove) {
	    	this.canMove = canMove;
	    }
	    
	    @Override
	    public void setBounds(Rectangle rect) {
	    	if (this.canMove || this.getBounds().width <= 0 || this.bounds.height <= 0) {
	    		super.setBounds(rect);
	    	}
	    }

}
